﻿using AutoMapper;
using B.S.Material.Domain.BOM;
using B.S.Material.Domain.Production_rejection;
using B.S.Material.ErrorCode;
using B.S.Material.Wirth.Api.Applications.Command.StrippingDetailsCommand;
using MediatR;
using SqlSugar;

namespace B.S.Material.Wirth.Api.Applications.Handler.StrippingDetailsHandler
{
    public class AddStrippingDetailsHandelr : IRequestHandler<AddStrippingDetailsCommand, ApiResult<object>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public AddStrippingDetailsHandelr(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        public async Task<ApiResult<object>> Handle(AddStrippingDetailsCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> result = new ApiResult<object>();
            result.Code = ApiEnum.添加成功;
            result.MAG = ApiEnum.添加成功.ToString();

            var model = mapper.Map<StrippingDetails>(request);
            model.IsDel = false;
            await db.Insertable(model).ExecuteCommandAsync();

            return await Task.FromResult(result);
        }
    }
}
